# 作者：lian

import os
def seek_start():
    """
    相对于开头进行偏移
    :return:
    """
    file = open('file3',mode='r+',encoding='utf8')
    file.seek(0,os.SEEK_SET)
    text = file.read(5)
    print(text)
    file.close()

def seek_end():
    file = open('file3',mode='r+',encoding='utf8')
    file.seek(0,os.SEEK_END)
    text = file.read(5)
    print(text) #读不到内容，是空字符串
    file.close()

def seek_cur():
    file = open('file1',mode='rb+')
    file.seek(5,os.SEEK_CUR)
    file.seek(-2,os.SEEK_CUR)
    file.seek(-3,os.SEEK_END)
    text = file.read(5)
    print(text) #读不到内容，是空字符串
    file.close()
def seek_b_cur():
    file = open('file1',mode='rb+')
    b=file.read()
    print(b)
    file.close()

def copy_file():
    file1 = open('shenda.png',mode='rb+')
    file2 = open('shenda_copy.png',mode='wb')
    b=file1.read()
    file2.write(b)
    file1.close()
    file2.close()


def modify_moive():
    file1 = open('shenda.png',mode = 'rb+')
    file1.seek(10,os.SEEK_SET)
    b = file1.read(1)
    inverted_b = bytes(~b[0]& 0xFF)

    file1.seek(10,os.SEEK_SET)
    file1.write(inverted_b)
    file1.close()


if __name__ == '__main__':
    modify_moive()
